<?php
/**
 * Message entity.
 *  
 * @author james
 *
 */
class Message extends Zend_Db_Table_Abstract { 
	protected $_name = 'message';
	protected $_primary = 'id';
	
	protected $_dependentTables = array(
		'InvitationMessage',
		'UserMessage'
	);
	protected $_referenceMap    = array(
		'User' => array(
			'columns' => 'user_id',
			'refTableClass' => 'User',
			'refColumns' => 'id'
		)
	);
	
	/**
	 * Get user of given message.
	 * 
	 * @param $id message
	 */
	public static function getUser($message) {
		return $message->findParentRow('User');
	}
	
	/**
	 * Post a message.
	 * 
	 * @param $data insert data
	 */
	public function postMessage($data) {
		return $this->insert($data);
	}
	
	/**
	 * Delete by id.
	 * 
	 * @param $message_id
	 */
	public function deleteById($message_id) {
		$this->delete('id='.$message_id);
	}
}

?>